home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / pccp019.zip / EMUED.C < prev    next >
C/C++ Source or Header  |  1992-04-30  |  8KB  |  275 lines

  1. /*    Copyright (C) 1992 Peter Edward Cann, all rights reserved.
  2.  *    MicroSoft QuickC: >qcl emued.c graphics.lib
  3.  */
  4.  
  5. #include<stdio.h>
  6. #include<fcntl.h>
  7. #include<sys\types.h>
  8. #include<sys\stat.h>
  9. #include<bios.h>
  10. #include<graph.h>
  11. #include"emu.h"
  12.  
  13. main(argc, argv)
  14.     int argc;
  15.     char **argv;
  16.     {
  17.     int emufd, major, minor, scan, value;
  18.     char c, fpname[256];
  19.     _settextposition(25,1);
  20.     printf("Copyright (C) 1992 Peter Edward Cann, all rights reserved.\n");
  21.     printf("You may set the environment variable TERMPATH.\n");
  22.     printf("If not set we use the current directory.\n\n");
  23.     if(!strcmp(getenv("REMOTE"), "YES"))
  24.         {
  25.         printf("You appear to be logged in remotely, judging by the environment\n");
  26.         printf("variable REMOTE, so this is probably a very bad idea.\n");
  27.         printf("Are you sure you want to run EMUED? (y or n) --> ");
  28.         if(getchar()!='y') /* Note getchar() and not getch()! */
  29.             {
  30.             printf("I didn't think so!\n");
  31.             exit(99);
  32.             }
  33.         else
  34.             printf("OK, you're the boss!\n");
  35.         }
  36.     if(argc!=2)
  37.         {
  38.         printf("USAGE: emued <emu file basename>\n");
  39.         exit(1);
  40.         }
  41.     if(getenv("TERMPATH")==NULL)
  42.         sprintf(fpname, "%s.emu", argv[1]);
  43.     else
  44.         sprintf(fpname, "%s\\%s.emu", getenv("TERMPATH"), argv[1]);
  45.     if((emufd=open(fpname, O_RDONLY|O_BINARY))==-1)
  46.         {
  47.         printf("Error opening existing emu file %s for read.\nStarting from scratch.\n\n", fpname);
  48.         nullemu();
  49.         }
  50.     else if(read(emufd, &emu, sizeof(emu))!=sizeof(emu))
  51.         {
  52.         printf("Error reading existing emu file %s.\nStarting from scratch.\n\n", fpname);
  53.         nullemu();
  54.         }
  55.     if(emufd!=-1)
  56.         close(emufd);
  57.     if((emufd=open(fpname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, S_IWRITE))==-1)
  58.         {
  59.         printf("Error opening emu file for write.\n");
  60.         exit(2);
  61.         }
  62.     printf("You should have a copy of emu.h to consult to program display functions.\n\n");
  63.     printf("Making a variable length substitution token last in a\n");
  64.     printf("function sequence is highly questionable.\n\n");
  65.     printf("tophi_p = %d {1 => top row is 24; 0 => top is 1}\n", (int)emu.tophi_p);
  66.     printf("Binary row offset = %02x\n", emu.binrowoff);
  67.     printf("Binary column offset = %02x\n", emu.bincoloff);
  68.     printf("default_wrap_p = %d\n", emu.default_wrap_p);
  69.     printf("Modify? --> ");
  70.     if(getch()=='y')
  71.         {
  72.         printf("y\nEnter tophi_p (0 or 1): --> ");
  73.         scanf("%d", &value);
  74.         emu.tophi_p=value;
  75.         printf("Enter binary row offset (hex): --> ");
  76.         scanf("%x", &value);
  77.         emu.binrowoff=value;
  78.         printf("Enter binary column offset (hex): --> ");
  79.         scanf("%x", &value);
  80.         emu.bincoloff=value;
  81.         printf("Enter default_wrap_p (0 or 1): --> ");
  82.         scanf("%d", &value);
  83.         emu.default_wrap_p=value;
  84.         }
  85.     else
  86.         printf("n\n");
  87.     while(1)
  88.         {
  89.         printf("\n\nk(ey), f(unc), g(raphics char) or e(xit)? --> ");
  90.         c=getch();
  91.         printf("%c\n", c);
  92.         if(c=='k')
  93.             {
  94.             printf("Operate the key --> ");
  95.             while(!_bios_keybrd(_KEYBRD_READY));
  96.             major=_bios_keybrd(_KEYBRD_READ);
  97.             if(major&0xff)
  98.                 printf("\n\007Not a programmable key!\n");
  99.             else
  100.                 {
  101.                 major=(major>>8)&0xff;
  102.                 printf("\nScancode 0x%02x selected.", major);
  103.                 if(emu.keys[major].nullpause_p)
  104.                     printf("  Zero presently means pause 1.1 seconds and ff means break.\n");
  105.                 else
  106.                     printf("  No special translations are in effect.\n");
  107.                 printf("Present contents (blank line means empty):\n");
  108.                 for(minor=0;minor<emu.keys[major].len;++minor)
  109.                     printf(" %02x", emu.keys[major].chars[minor]);
  110.                 printf("\nModify? (y or n): --> ");
  111.                 if(getch()=='y')
  112.                     {
  113.                     printf("y\nZero means 1.1 sec pause and ff means break? (y or n): --> ");
  114.                     if(getch()=='y')
  115.                         {
  116.                         printf("y\n");
  117.                         emu.keys[major].nullpause_p=1;
  118.                         }
  119.                     else
  120.                         {
  121.                         printf("n\n");
  122.                         emu.keys[major].nullpause_p=0;
  123.                         }
  124.                     printf("Enter chars (up to %d). INSERT to enter in hex. END to end:\n-->\n\n", KEYLEN);
  125.                     _settextposition(23,4);
  126.                     minor=0;
  127.                     while(1)
  128.                         {
  129.                         value=_bios_keybrd(_KEYBRD_READ);
  130.                         if(value==0x5200)
  131.                             {
  132.                             printf("\nEnter hex code: --> ");
  133.                             scanf("%x", &value);
  134.                             _settextposition(24,1);
  135.                             printf("\t\t\t\t\t\t\t\t\t\r");
  136.                             }
  137.                         else
  138.                             if(value==0x4f00)
  139.                                 value=END;
  140.                             else
  141.                                 value&=0xff;
  142.                         if(value==END)
  143.                             {
  144.                             printf("\n");
  145.                             emu.keys[major].len=minor;
  146.                             break;
  147.                             }
  148.                         else
  149.                             if(minor<KEYLEN)
  150.                                 {
  151.                                 emu.keys[major].chars[minor++]=value;
  152.                                 _settextposition(23,1);
  153.                                 for(scan=0;scan<minor;scan++)
  154.                                     printf(" %02x", emu.keys[major].chars[scan]);
  155.                                 printf(" -->");
  156.                                 }
  157.                             else
  158.                                 {
  159.                                 printf("\nExcess char ignored.\n");
  160.                                 emu.keys[major].len=KEYLEN;
  161.                                 break;
  162.                                 }
  163.                             }
  164.                     }
  165.                 else
  166.                     printf("n\n");
  167.                 }
  168.             }
  169.         if(c=='f')
  170.             {
  171.             printf("Sequence number (decimal): --> ");
  172.             scanf("%d", &major);
  173.             if((major<0)||(major>=NFUNCS))
  174.                 printf("Bad sequence number.\n");
  175.             else
  176.                 {
  177.                 printf("Function is presently #%d decimal.\n", emu.funcs[major].func);
  178.                 for(minor=0;emu.funcs[major].codes[minor]!=END;++minor)
  179.                     printf(" %03x", emu.funcs[major].codes[minor]);
  180.                 printf("\nModify? (y or n): --> ");
  181.                 if(getch()=='y')
  182.                     {
  183.                     printf("y\nEnter function number in decimal. --> ");
  184.                     scanf("%d", &value);
  185.                     if((value<0)||(value>NOOP))
  186.                         printf("Bad function number.\n");
  187.                     else
  188.                         {
  189.                         emu.funcs[major].func=value;
  190.                         printf("Enter chars (up to %d). INSERT to enter in hex. END at end:\n-->\n\n", FUNLEN-1);
  191.                         _settextposition(23,4);
  192.                         minor=0;
  193.                         while(1)
  194.                             {
  195.                             value=_bios_keybrd(_KEYBRD_READ);
  196.                             if(value==0x5200)
  197.                                 {
  198.                                 printf("\nEnter hex code: --> ");
  199.                                 scanf("%x", &value);
  200.                                 _settextposition(24,1);
  201.                                 printf("\t\t\t\t\t\t\t\r");
  202.                                 }
  203.                             else
  204.                                 if(value==0x4f00)
  205.                                     value=END;
  206.                                 else
  207.                                     value&=0xff;
  208.                             emu.funcs[major].codes[minor++]=value;
  209.                             if(value==END)
  210.                                 {
  211.                                 printf("\n");
  212.                                 break;
  213.                                 }
  214.                             else
  215.                                 if(minor<FUNLEN)
  216.                                     {
  217.  
  218.                                     _settextposition(23,1);
  219.                                     for(scan=0;scan<minor;scan++)
  220.                                         printf(" %03x", emu.funcs[major].codes[scan]);
  221.                                     printf(" -->");
  222.                                     }
  223.                                 else
  224.                                     {
  225.                                     minor--;
  226.                                     printf("\nExcess code ignored.\n");
  227.                                     emu.funcs[major].codes[FUNLEN-1]=END;
  228.                                     break;
  229.                                     }
  230.                             }
  231.                         }
  232.                     }
  233.                 else
  234.                     printf("n\n");
  235.                 }
  236.             }
  237.         if(c=='g')
  238.             {
  239.             printf("Enter char or INSERT to enter in hex: --> ");
  240.             value=_bios_keybrd(_KEYBRD_READ);
  241.             if(value==0x5200)
  242.                 {
  243.                 printf("Enter hex: --> ");
  244.                 scanf("%x", &value);
  245.                 }
  246.             else
  247.                 {
  248.                 value&=0xff;
  249.                 printf("%c\n", value);
  250.                 }
  251.             if(emu.gchars[value])
  252.                 printf("Hex code %02x  Current char: -->%c<--  Modify? (y or n) --> ", value, emu.gchars[value]);
  253.             else
  254.                 printf("Hex code %02x  Current char is zero (unspecified).  Modify? (y or n) --> ", value);
  255.             if(getch()=='y')
  256.                 {
  257.                 printf("y\nEnter hex code of new graphics character: --> ");
  258.                 scanf("%x", &emu.gchars[value]);
  259.                 if(emu.gchars[value])
  260.                     printf("gchar %02x hex is now: -->%c<--\n", value, emu.gchars[value]);
  261.                 else
  262.                     printf("gchar %02x hex is now zero (unspecified).\n", value);
  263.                 }
  264.             else
  265.                 printf("n\n");
  266.             }
  267.         if(c=='e')
  268.             break;
  269.         }
  270.     if(write(emufd, &emu, sizeof(emu))!=sizeof(emu))
  271.         printf("Damn!  Couldn't write the file!\n");
  272.     close(emufd);
  273.     exit(0);
  274.     }
  275.